package com.king.common.lang;

import java.io.Serializable;

public class Result implements Serializable {
    public int code;
    private String msg;
    private Object data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    private Result() {
    }

    public static Result success(Object data) {
        return custom(ResultEnum.SUCCESS.getCode(),ResultEnum.SUCCESS.getMsg(),data);
    }

    public static Result fail(String msg) {
        return custom(ResultEnum.FAIL.getCode(),msg,null);
    }

    public static Result custom(int code, String msg, Object data) {
        Result r = new Result();
        r.code = code;
        r.msg = msg;
        r.data = data;
        return r;
    }
}

enum ResultEnum {
    SUCCESS(200, "操作成功！"),
    FAIL(400, "操作失败！"),
    ;

    private int code;
    private String msg;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    ResultEnum(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }
}
